from keras.models import load_model
from PredictAllCells.train_all_cells import create_dataset
import numpy as np

'''
    函数 predict_all_cells
        参数：
            model_path:模型存储路径
            data: 待预测的数据
        返回值：
            predict_value:预测的结果，维度为：[小时数，格子行数，格子列数]
            true_value   :真实的结果，维度为：[小时数，格子行数，格子列数]
'''


def predict_all_cells(model_path, data, rows, columns, time_step):
    matrix_dimension = rows * columns
    # load model
    model = load_model(model_path)
    predict_data, true_data, scaler = create_dataset(data, time_step)
    predict_data = predict_data.reshape([-1, time_step, matrix_dimension])
    true_data = true_data.reshape([-1, matrix_dimension])
    res_trans = model.predict(predict_data)
    true_data = scaler.inverse_transform(true_data)
    res = scaler.inverse_transform(res_trans)
    true_data = np.trunc(true_data)
    res = np.trunc(res)
    true_data = true_data.reshape(-1, rows, columns)
    res = res.reshape(-1, rows, columns)

    return res, true_data
